package com.che.software.testato.util.jsf.faces;

import java.io.Serializable;

import javax.faces.context.FacesContext;

import org.apache.log4j.Logger;

/**
 * Static class used to facilitate the use of the faces.
 * 
 * @author Clement HELIOU (clement.heliou@che-software.com).
 * @copyright Che Software.
 * @license GNU General Public License.
 * @see Serializable.
 * @since July, 2011.
 * 
 *        This file is part of Testato.
 * 
 *        Testato is free software: you can redistribute it and/or modify it
 *        under the terms of the GNU General Public License as published by the
 *        Free Software Foundation, either version 3 of the License, or (at your
 *        option) any later version.
 * 
 *        Testato is distributed in the hope that it will be useful, but WITHOUT
 *        ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *        FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 *        for more details.
 * 
 *        You should have received a copy of the GNU General Public License
 *        along with Testato. If not, see <http://www.gnu.org/licenses/>.
 * 
 *        Testato's logo is a creation of Arrioch
 *        (http://arrioch.deviantart.com/) and it's distributed under the terms
 *        of the Creative Commons License.
 */
public class FacesUtil implements Serializable {

	/**
	 * Constants.
	 */
	private static final Logger LOGGER = Logger.getLogger(FacesUtil.class);
	private static final long serialVersionUID = -7337548289437644982L;

	/**
	 * Private default builder; this a static class.
	 */
	private FacesUtil() {
	}

	/**
	 * Retrieves a controller in the JSF session from his name.
	 * 
	 * @author Clement HELIOU (clement.heliou@che-software.com).
	 * @param controllerName the looked for controller name.
	 * @return the resulting object.
	 * @since July, 2011.
	 */
	public static Object getControllerFromName(String controllerName) {
		LOGGER.debug("getControllerFromName(" + controllerName + ").");
		return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(controllerName);
	}
}
